package com.example.demoweb.config;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class JDK8DateDemo4 {
    public static void main(String[] args) {

//        method1();
        // 解析
        // public static LocalDateTime parse (准备解析的字符串，解析格式) 把一个日期字符串解析成一个字符串
        method3();
    }

    private static void method1() {
        LocalDateTime localDateTime = LocalDateTime.of(2020, 12, 12, 12, 12, 12);
        System.out.println(localDateTime);
        // public String format (指定格式)   把一个LocalDateTime格式化成为一个字符串
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        String format = localDateTime.format(pattern);
        System.out.println(format);
    }

    public static void method2() {
        String s = "2020年12月12日 12:13:14";
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(s, pattern);
        System.out.println(parse);
    }

    public static void method3() {
        String s = "20201210 10:00:12";
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyyMMdd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(s, pattern);
        System.out.println(parse);
    }
}

